package com.work.music.dao;

import com.work.music.entity.UserWord;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.type.JdbcType;
import org.springframework.stereotype.Repository;

@Repository
public interface UserWordMapper {
    @Delete({
        "delete from music_user_word",
        "where uid = #{uid,jdbcType=BIGINT}",
          "and wordid = #{wordid,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(@Param("uid") Long uid, @Param("wordid") Long wordid);

    @Insert({
        "insert into music_user_word (uid, wordid, ",
        "addtime, addip)",
        "values (#{uid,jdbcType=BIGINT}, #{wordid,jdbcType=BIGINT}, ",
        "#{addtime,jdbcType=TIMESTAMP}, #{addip,jdbcType=VARCHAR})"
    })
    int insert(UserWord record);

    @Select({
        "select",
        "uid, wordid, addtime, addip",
        "from music_user_word",
        "where uid = #{uid,jdbcType=BIGINT}",
          "and wordid = #{wordid,jdbcType=BIGINT}"
    })
    @Results({
        @Result(column="uid", property="uid", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="wordid", property="wordid", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="addtime", property="addtime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="addip", property="addip", jdbcType=JdbcType.VARCHAR)
    })
    UserWord selectByPrimaryKey(@Param("uid") Long uid, @Param("wordid") Long wordid);

    @Select({
        "select",
        "uid, wordid, addtime, addip",
        "from music_user_word"
    })
    @Results({
        @Result(column="uid", property="uid", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="wordid", property="wordid", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="addtime", property="addtime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="addip", property="addip", jdbcType=JdbcType.VARCHAR)
    })
    List<UserWord> selectAll();

    @Update({
        "update music_user_word",
        "set addtime = #{addtime,jdbcType=TIMESTAMP},",
          "addip = #{addip,jdbcType=VARCHAR}",
        "where uid = #{uid,jdbcType=BIGINT}",
          "and wordid = #{wordid,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(UserWord record);
}